{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def mean_squared_error(y_true, y_pred):\n",
    "    return np.mean(np.square(y_pred - y_true), axis=-1)\n",
    "\n",
    "\n",
    "def mean_absolute_error(y_true, y_pred):\n",
    "    return np.mean(np.abs(y_pred - y_true), axis=-1)\n",
    "\n",
    "\n",
    "def mean_squared_logarithmic_error(y_true, y_pred):\n",
    "    first_log = np.log(np.clip(y_pred, 10e-6, None) + 1.)\n",
    "    second_log = np.log(np.clip(y_true, 10e-6, None) + 1.)\n",
    "    return np.mean(np.square(first_log - second_log), axis=-1)\n",
    "\n",
    "\n",
    "def mean_absolute_percentage_error(y_true, y_pred):\n",
    "    diff = np.abs((y_pred - y_true) / np.clip(np.abs(y_true), 10e-6, None))\n",
    "    return 100 * np.mean(diff, axis=-1)\n",
    "\n",
    "\n",
    "def hinge(y_true, y_pred):\n",
    "    return np.mean(np.maximum(1. - y_true * y_pred, 0.), axis=-1)\n",
    "\n",
    "\n",
    "def cross_entropy(y_true, y_pred):\n",
    "    return -np.mean(y_true * np.log(y_pred + 10e-6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
